package com.why.serviceedu.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.why.commonresults.Result;
import com.why.serviceedu.bean.EduCourse;
import com.why.serviceedu.service.EduCourseService;
import com.why.serviceedu.bean.EduTeacher;
import com.why.serviceedu.service.EduTeacherService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: guli_parent
 * @description:
 * @author: @why
 * @create: 2021-02-20 18:01
 **/
@RestController
@RequestMapping("/eduservice/edu-teacher")
@CrossOrigin
public class FrontTeacherController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    /**
     * 分页查询讲师
     */
    @GetMapping("/getteacher/{current}/{limit}")
    public Result getTeachers(@PathVariable Long current,
                              @PathVariable Long limit){

        Page<EduTeacher> teacherPage = new Page<>(current,limit);
       Map<String, Object> result=  teacherService.getTeacherList(teacherPage);
        System.out.println(limit);
        //返回分页的所有数据
        return  Result.ok().data(result);
    }




    @ApiOperation(value = "根据ID查询讲师")
    @GetMapping(value = "getFrontTeacherInfo/{id}")
    public Result getById(
            @ApiParam(name = "id", value = "讲师ID", required = true)
            @PathVariable String id){
//查询讲师信息
        EduTeacher teacher = teacherService.getById(id);
//根据讲师id查询这个讲师的课程列表
        List<EduCourse> courseList = courseService.selectByTeacherId(id);
        return Result.ok().data("teacher", teacher).data("courseList", courseList);
    }

















}
